#include "MsgNode.h"

MsgNode::MsgNode(short total_len):_len(total_len),_cur_len(0)
{
	_data = new char[_len];
}

MsgNode::~MsgNode()
{
	std::cout << "~MsgNode" << std::endl;
	delete[] _data;
}

void MsgNode::Clear()
{
	memset(_data, 0, _len);
	_cur_len = 0;
}

RecvNode::RecvNode(short max_len, short msg_id):_msg_id(msg_id),MsgNode(max_len)
{
}

short RecvNode::GetMsgId() const
{
	return _msg_id;
}

SendNode::SendNode(const char* msg, short max_len, short msg_id):_msg_id(msg_id),MsgNode(max_len+HEAD_TOTAL_LEN)
{
	_data = new char[_len];
	short msg_id_net = boost::asio::detail::socket_ops::host_to_network_short(_msg_id);
	short msg_len_net = boost::asio::detail::socket_ops::host_to_network_short(max_len);
	memcpy(_data, &msg_id_net, HEAD_ID_LEN);
	memcpy(_data+HEAD_ID_LEN, &msg_len_net, HEAD_DATA_LEN);
	memcpy(_data + HEAD_TOTAL_LEN, msg, max_len);

}
